package com.shop.controller;

import com.shop.pojo.DtsIssue;
import com.shop.service.DtsIssueService;
import com.shop.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName AdminIssueController
 * @Author xiao宋
 * @Date 16:26  2022/10/22
 * @Version 1.0
 * @Description TODO
 */
@Slf4j
@RestController
@RequestMapping("/admin/issue")
public class AdminIssueController {
    @Autowired
    DtsIssueService issueService;

    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            String question
    ) {
        Map<String, Object> data = issueService.findByPage(page, limit, sort, order, question);
        return ResponseUtil.ok(data);
    }

    @PostMapping("/update")
    public Object update(DtsIssue issue) {
        issueService.update(issue);
        return ResponseUtil.ok();
    }
    @PostMapping("/create")
    public Object create(DtsIssue issue) {
        DtsIssue data = issueService.insert(issue);
        return ResponseUtil.ok(data);
    }
    @PostMapping("/delete")
    public Object delete(DtsIssue issue) {
         issueService.delete(issue);
        return ResponseUtil.ok();
    }
}
